#include "CString.h"

bool String::IsSubstring(const char* str)
{
	int m = strlen(str);
	int j;
	for (int i = 0; i + m <= len; i++)//一定有等于
	{
		for ( j= 0; j < m; )
		{
			if (str[j] == mystr[i + j])j++;
			else break;

		}
		if (j == m) return true;
		
	}
	return false;
}

bool String::IsSubstring(const String& str)
{
	return IsSubstring(str.mystr);
}

int String::str2num()
{
	int weight = 1, sum = 0;
	for(int i=len-1;i>=0;i--)
		if (mystr[i] >= '0' && mystr[i] <= '9')
		{
			sum += weight * (mystr[i] - '0');
			weight *= 10;
		}
	return sum;

}

void String::toUppercase()
{
	for(int i=0;i<len;i++)
		if (mystr[i] >= 'a' && mystr[i] <= 'z')
		{
			mystr[i] += 'A' - 'a';
		}
}